package cn.edu.hbsi.dao;

import cn.edu.hbsi.domain.Car;
import org.apache.ibatis.annotations.*;

public interface CarDao
{
    //根据司机id查询该司机的车
    @Results({
            @Result(id = true,property = "cId",column = "id"),
            @Result(property = "carInfo",column = "carinfo")
    })
    @Select("select * from de_car where driver_id=#{dId}")
    public Car selectCarByDId(@Param("dId") Integer dId);

    //根据气车id删除并同时删除对应的司机的信息
    @Delete("DELETE d,c FROM de_driver d JOIN de_car c ON d.id = c.driver_id WHERE c.id = #{cId}")
    public Integer deleteCarAndDriverByCId(@Param("cId") Integer cId);

    //根据气车id查询该汽车及其对应的司机
    @Results({
            @Result(id = true,property = "cId",column = "id"),
            @Result(property = "carInfo",column = "carinfo"),
            @Result(property = "driver",column = "driver_id",one = @One(select = "cn.edu.hbsi.dao.DriverDao.selectDriver"))
    })
    @Select("select * from de_car where id=#{cId}")
    public Car selectCarAndDriverByCId(@Param("cId") Integer cId);
}
